-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed non-existing path issue #67773
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
async function checkPathExists(path) { | ||
const response = await fetch(`/wp-json/wp/v2/templates${path}`); | ||
return response.ok; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea, though I this can be implemented as part of the routing code to avoid the need to fetch
asynchronously. In the site editor the routing is implemented here:
gutenberg/packages/edit-site/src/components/app/index.js
Lines 53 to 60 in 358fe48
return ( | |
<RouterProvider | |
routes={ routes } | |
pathArg="p" | |
beforeNavigate={ beforeNavigate } | |
> | |
<AppLayout /> | |
</RouterProvider> |
The routes
come from this file:
https://github.com/WordPress/gutenberg/blob/trunk/packages/edit-site/src/components/site-editor-routes/index.js
The implementation is using the router
package as a library. I can see that there's some handling for 404 here:
gutenberg/packages/router/src/router.tsx
Lines 163 to 172 in 8e048a8
if ( ! result ) { | |
return { | |
name: '404', | |
path: addQueryArgs( path, query ), | |
areas: {}, | |
widths: {}, | |
query, | |
params: {}, | |
}; | |
} |
I'm not familiar with the code though, so I don't know how to make this display something. Perhaps it should be possible to define a 404
route in the site editor package
Part of #67445
What?
Site Editor should display a 404 message when you navigate to a non-existing path
Why?
Currently, the Site Editor is showing a black page with no message or content when the user miss-type the link
How?
It will show a 404 message with a button to get back to the site editor.
Testing Instructions
Try navigating to wp-admin/site-editor.php?p=%2Ftemplate-fdgfdgdfg
Screenshots or screencast
fix-non-existing-path.mp4